using System;
using Kopernikus.Parsing.Utility;

namespace Kopernikus.Parsing.Earley
{
    public struct EarleyItem : IEquatable<EarleyItem>
    {
        public static readonly EarleyItem None = Create(-1, -1);
        private Pair<int, int> m_data;

        public int State
        {
            get { return m_data.First; }
        }

        public int Parent
        {
            get { return m_data.Second; }
        }

        #region Object overrides

        public override string ToString()
        {
            return m_data.ToString();
        }

        public override bool Equals(object obj)
        {
            return Equals((EarleyItem) obj);
        }

        public override int GetHashCode()
        {
            return m_data.GetHashCode();
        }

        #endregion

        #region IEquatable<EarleyItem> Members

        public bool Equals(EarleyItem other)
        {
            return m_data.Equals(other.m_data);
        }

        #endregion

        public static EarleyItem Create(int state, int parent)
        {
            EarleyItem earleyItem;
            earleyItem.m_data = Pair<int, int>.Create(state, parent);
            return earleyItem;
        }
    }
}